export default {

	/**
	 * 字符串格式化
	 */
	format: function(formatted, args) {
		for (let i = 0; i < args.length; i++) {
			let regexp = new RegExp('\\{' + i + '\\}', 'gi')
			formatted = formatted.replace(regexp, args[i])
		}
		return formatted;
	},
	isPow: function(str) {
		
		return !/^(?:(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])).{8,12}$/.test(str);
	},
	isIdentityCard4: function(str) {
		//return !/^(?![da-z]+$)(?![dA-Z]+$)(?![d!#$%^&*]+$)(?![a-zA-Z]+$)(?![a-z!#$%^&*]+$)(?![A-Z!#$%^&*]+$)[da-zA-z!#$%^&*]{6,12}$/.test(str);
		return !/^\d{3}[0-9X]{1}$/.test(str)
	},
	isNumber4: function(str) {
		//return !/^(?![da-z]+$)(?![dA-Z]+$)(?![d!#$%^&*]+$)(?![a-zA-Z]+$)(?![a-z!#$%^&*]+$)(?![A-Z!#$%^&*]+$)[da-zA-z!#$%^&*]{6,12}$/.test(str);
		return !/^\d{4}$/.test(str)
	},
	isPhoto: function(str) {
		//return !/^(?![da-z]+$)(?![dA-Z]+$)(?![d!#$%^&*]+$)(?![a-zA-Z]+$)(?![a-z!#$%^&*]+$)(?![A-Z!#$%^&*]+$)[da-zA-z!#$%^&*]{6,12}$/.test(str);
		return !/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(str);
	},
	isString: function(str) {
		if (typeof str === 'string' || str instanceof String) {
			return true
		}
		return false
	},
	isArray: function(arg) {
		if (typeof Array.isArray === 'undefined') {
			return Object.prototype.toString.call(arg) === '[object Array]';
		}
		return Array.isArray(arg)
	},
  formatDate: function(dateParam, fmt){
    var date;
    console.log("日期格式化：" + dateParam + " 格式化为：" + fmt + " 参数类型为：" + typeof dateParam);
    if(typeof dateParam == 'string'){
      console.log("参数为字符串类型：" + dateParam);
      date = new Date(dateParam);
    } else {
      date = dateParam;
    }
    if(date == undefined || date == "" || date == null){
      return "";
    }
    if(fmt == undefined){
      fmt = "yyyy-MM-dd hh:mm:ss";
    }
    if(/(y+)/.test(fmt)){
      fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
    }
    let o = {
      'M+': date.getMonth() + 1,
      'd+': date.getDate(),
      'h+': date.getHours(),
      'm+': date.getMinutes(),
      's+': date.getSeconds()
    }
    for (let k in o) {
      if (new RegExp(`(${k})`).test(fmt)) {
        let str = o[k] + ''
        fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str))
      }
    }
    return fmt
  },
  padLeftZero: function(str) {
    return ('00' + str).substr(str.length)
  },
  isNotNullOrEmpty: function(str){
    if(str != undefined && str != null && str != "" && str.toString().replace(/(^\s*)|(\s*$)/g, "") != ""){
      return str;
    }
  },
  checkNum :function (e) {
  	let val = e.target.value.replace(/(^\s*)|(\s*$)/g, "")
  	if (!val) {
  		return ''
  	}
  	var reg = /[^\d.]/g
  	// 只能是数字和小数点，不能是其他输入
  	val = val.replace(reg, "")
  	// // 保证第一位只能是数字，不能是点
  	val = val.replace(/^\./g, "");
  	// // 小数只能出现1位
  	val = val.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
  	// // 小数点后面保留2位
  	val = val.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');
  	console.log(val);
  	return val
  }

}
